#!/usr/bin/env python3

import os
import subprocess

def set_wallpaper(image_path):
    """设置壁纸，根据不同的桌面环境使用不同的命令"""
    desktop_env = os.environ.get('XDG_CURRENT_DESKTOP', '').lower()
    
    try:
        if 'gnome' in desktop_env or 'ubuntu' in desktop_env:
            # GNOME、Unity
            subprocess.run([
                'gsettings', 'set', 
                'org.gnome.desktop.background', 
                'picture-uri', 
                f'file://{image_path}'
            ], check=True)
        elif 'kde' in desktop_env:
            # KDE Plasma
            subprocess.run([
                'plasma-apply-wallpaperimage', image_path
            ], check=True)
        elif 'xfce' in desktop_env:
            # XFCE
            subprocess.run([
                'xfconf-query', '-c', 'xfce4-desktop', 
                '-p', '/backdrop/screen0/monitor0/image-path', 
                '-s', image_path
            ], check=True)
        else:
            # 通用方法（尝试feh）
            subprocess.run(['feh', '--bg-scale', image_path], check=True)
        
        print(f"壁纸已恢复为默认: {image_path}")
        return True
    except subprocess.CalledProcessError as e:
        print(f"设置壁纸失败: {e}")
        return False

if __name__ == "__main__":
    # 默认壁纸路径
    default_wallpaper = os.path.expanduser("/usr/share/wallpapers/deepin/luke-stackpoole-mStq-dtsXCQ-unsplash.jpg")
    set_wallpaper(default_wallpaper)